package cn.net.shuxing.yifu.common.back.controller;

import cn.net.shuxing.yifu.common.bean.ContentHelper;
import cn.net.shuxing.yifu.common.bean.ContentProtocal;
import cn.net.shuxing.yifu.common.bean.ContentQuestion;
import cn.net.shuxing.yifu.common.bean.HelperClass;
import cn.net.shuxing.yifu.common.dto.BaseDto;
import cn.net.shuxing.yifu.common.mapper.ContentProtocalMapper;
import cn.net.shuxing.yifu.common.service.ContentHelperService;
import cn.net.shuxing.yifu.common.service.ContentProtocalService;
import cn.net.shuxing.yifu.common.service.ContentQuestionService;
import cn.net.shuxing.yifu.common.service.HelperClassService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/front")
public class FrontContentController {

    @Autowired
    private ContentQuestionService contentQuestionService;

    @Autowired
    private HelperClassService helperClassService;

    @Autowired
    private ContentHelperService contentHelperService;

    @Autowired
    private ContentProtocalService contentProtocalService;

    /**
     * 查询所有常见问题
     *
     * @return
     */
    @RequestMapping("/content/question")
    public BaseDto questionList(int userId,
                                @RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                @RequestParam(defaultValue = "15", value = "pageSize") int pageSize) {
        BaseDto baseDto = new BaseDto();
        baseDto.setData(contentQuestionService.getAll());
        return baseDto;
    }

    /**
     * 查询所有隐私协议
     *
     * @return
     */
    @RequestMapping("/content/protocal")
    public BaseDto protocalList(int userId) {
        BaseDto baseDto = new BaseDto();
        ContentProtocal contentProtocal = contentProtocalService.getLastRow();
        baseDto.setData(contentProtocal);
        return baseDto;
    }


    /**
     * 查询所有帮助中心类别
     *
     * @return
     */
    @RequestMapping("/content/helperclass")
    public BaseDto questionClasses() {
        BaseDto baseDto = new BaseDto();
        List<HelperClass> helperClasses = helperClassService.getAll();
        baseDto.setData(helperClasses);
        return baseDto;
    }


    /**
     * 查询所有帮助中心类别下的常见问题
     *
     * @return
     */
    @RequestMapping("/content/helper")
    public BaseDto questionByClasses(int classId) {
        BaseDto baseDto = new BaseDto();
        List<ContentHelper> contentHelperList = contentHelperService.selectByClassId(classId);
        baseDto.setData(contentHelperList);
        return baseDto;
    }
}